//
//  ConsigneeListCell.m
//  ProjectforHDX
//
//  Created by Jaesun on 16/8/1.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "ConsigneeListCell.h"

@implementation ConsigneeListCell

- (void)setDataDic:(NSDictionary *)dataDic {
    _dataDic = dataDic;
    [self s_setupCellVieWithDataDic:dataDic];
}

- (void)s_setupCellVieWithDataDic:(NSDictionary *)dataDic {
    
    CGFloat width = [self widthForText:[dataDic objectForKey:@"username"]];
    if (width <= 70.f) {
        width = 70.f;
    }
    RZCustomLable *nameLab = [[RZCustomLable alloc] initWithFrame:CGRectMake(15, 0, width, 40)];
    nameLab.font = CustomFont(14);
    nameLab.text = [dataDic objectForKey:@"username"];
    [self.contentView addSubview:nameLab];
    
    RZCustomLable *telLab = [[RZCustomLable alloc] initWithFrame:CGRectMake(nameLab.right + 5, 0, 100, 40)];
    telLab.font = CustomFont(14);
    telLab.text = [dataDic objectForKey:@"tel"];
    [self.contentView addSubview:telLab];
    
    UIImage *editImg = BDFILEIMAGENAEM(@"UserCenter/consignee_edit");
    
    RZCustomButtom *editImgBtn = [[RZCustomButtom alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 80, (self.height - editImg.size.height) / 2, editImg.size.width, editImg.size.height)];
    [editImgBtn setImage:editImg forState:(UIControlStateNormal)];
    [editImgBtn addTarget:self action:@selector(touchEidtBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.contentView addSubview:editImgBtn];
    
    UIImage *delImg = BDFILEIMAGENAEM(@"UserCenter/consignee_del");
    RZCustomButtom *delImgBtn = [[RZCustomButtom alloc] initWithFrame:CGRectMake(editImgBtn.right + 25, (self.height - delImg.size.height) / 2, delImg.size.width, delImg.size.height)];
    [delImgBtn setImage:delImg forState:(UIControlStateNormal)];
    [delImgBtn addTarget:self action:@selector(touchDelBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.contentView addSubview:delImgBtn];
    
}

- (CGFloat)widthForText:(NSString *)text {
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(LONG_MAX, 15) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:CustomFont(13)} context:nil];
    
    return rect.size.width;
}

- (void)touchEidtBtn:(RZCustomButtom *)sender {
    _editBlock();
}

- (void)touchDelBtn:(RZCustomButtom *)sender {
    _delBlcok();
}

@end
